
import cn.evun.tms.common.controller.BaseController;
import cn.evun.tms.common.dto.DataPage;
import cn.evun.tms.common.dto.FormResult;
import cn.evun.tms.common.enums.ResultEnum;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
* Controller
*/
@Controller
@RequestMapping("/${url}")
public class ${me.className} extends BaseController {

	@Autowired
	private ${me.serviceInfo.className} ${lowerEntityName}Service;

	@RequestMapping(value = "/show", method = RequestMethod.GET)
	public String show(Model model) {
		model.addAttribute("moduleid", request.getParameter("moduleid"));
		return "tm/${url}-show";
	}

	@RequestMapping(value = "/list", method = RequestMethod.GET)
	@ResponseBody
	public DataPage<${me.dtoInfo.className}> showPageData( ) {
		return ${lowerEntityName}Service.showPageData(request);
	}

	@RequestMapping(value = "/edit", method = RequestMethod.GET)
	@ResponseBody
	public ${me.dtoInfo.className} load(Integer id) {
		if (null != id && 0 <= id) {
			return ${lowerEntityName}Service.load(id);
		}
		return null;
	}

	@RequestMapping(value = "/add", method = RequestMethod.GET)
	public String open() {
		return "tm/${url}-info";
	}

	@ResponseBody
	@RequestMapping(value = "/save", method = RequestMethod.POST)
	public FormResult<Object> save(@Validated ${me.dtoInfo.className} ${lowerEntityName}Dto) {
		FormResult<Object> result = new FormResult<>();
		${me.dtoInfo.className} data = ${lowerEntityName}Service.save(${lowerEntityName}Dto);
		result.setData(data.getId() + "");
		result.setMessage(ResultEnum.SYS_EXE_SUCCESS.getMsg());
		result.setState(ResultEnum.SYS_EXE_SUCCESS.getState());
		return result;
	}

	@RequestMapping(value = "/del", method = RequestMethod.POST)
	@ResponseBody
	public FormResult
	<Object> delete(String ids) {
		FormResult<Object> result = new FormResult<>();
		Integer count = ${lowerEntityName}Service.delete(ids);
		result.setData(count.toString());
		result.setMessage(MessageFormat.format(ResultEnum.SYS_DELETE_SUCCESS.getMsg(), count));
		result.setState(ResultEnum.SYS_DELETE_SUCCESS.getState());
		return result;
	}

}
